class Student(object):
    def __init__(self,name,age,college,grade):
        self.name = name
        self.age = age
        self.college = college
        self.grade = grade
    def sum(self):
        print(grade.get('yuwen',0) + grade.get('shuxue',0) + grade.get('yingyu',0))
    def avg(self):
        s=0
        for i in grade.values():    #用get或for循环获取总分
            s=s+i
        print('%.2f' %(s/3))
grade = {"yuwen": 87, "shuxue": 100, "yingyu": 100}
stu1 = Student('zz',18,'湖南农大',grade)
print()
stu1.sum()
stu1.avg()


class Bus317(object):
    line = "317"
    #lst1 = [1,2]
    name = "BUS"
    def __init__(self, car_num, name):  # 属于类的构造函数，可以初始化一些任务，它在类的一个对象被建立后自动运行
        self.name = name
        self.car_num = car_num
        self.age = 18
        self.line = "318"
        self.lst1 = [1,3]

    def run(self, flag):
        print("bus317 run")
        if flag == 0:
            print("从a站到c站")
        else:
            print("从c站到a站")


bus01 = Bus317("湘A2318","AA")  #实例化对象
print("Bus317.line:",Bus317.line)
print("bus.line:",bus01.line) #使用对象的属性
print(bus01.run(1)) #使用对象的方法

#添加实例属性
bus01.color = "red"
print("bus01.color:",bus01.color)
#添加类属性
Bus317.color = "green"
print("Bus317.color:",Bus317.color)
#修改实例属性
bus01.name = "BB"
print("bus01.name:",bus01.name)
#修改类属性
Bus317.name = "bus"
print("Bus317.nmae:",Bus317.name)

#删除实例属性，之后再输出该实例属性，若类属性中有与之同名的属性，输出的会是与之同名的类属性；否则会报错
del bus01.lst1
#print(bus01.lst1)

#删除类属性
del Bus317.lst1
#print("Bus317.lst1:",Bus317.lst1)  #再输出会报错

